#ifndef LOG_ASYNC_FILE_SINK_H
#define LOG_ASYNC_FILE_SINK_H

#include <log/async_sink.h>
#include <unistd.h>

namespace log {

class AsyncFileSink : public AsyncSink 
{
    public:
        AsyncFileSink();
        virtual ~AsyncFileSink() override;
    
    public:
        void cleanup();

        void setFilePath(const std::string &file_path);
        void setFilePrefix(const std::string &file_path);
        void setFileSyncEnable(bool enable);
        std::string currentFilename() const { return log_filename_; }
    
    protected:
        void updateInnerValues();

        virtual void appendLog(const char *str, size_t len);
        virtual void flushLog();

        bool checkAndCreateLogFile();

    private:
        std::string file_prefix_ = "none";
        std::string file_path_ = "/var/log/";
        bool file_sync_enable_ = false;
        pid_t pid_ = 0;

        std::string filename_prefix_;
        std::string sym_filename_;
        std::string log_filename_;

        std::vector<char> buffer_;

        int fd_ = -1; 
        size_t total_write_size_ = 0;

};

}

#endif
